﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using zijian666.Core.Abstractions;
using zijian666.DI;


namespace UnitTests;

[TestClass]
public class 泛型装配测试
{
    [TestMethod]
    public void 泛型装配()
    {
        var services = new ServiceCollection().AddTransient<MyClass2>();
        services.Add(new ServiceDescriptor(typeof(MyClass<>), typeof(MyClass<>), ServiceLifetime.Singleton));
        services.AddAutowired();
        var p = services.BuildServiceProvider();

        var my = p.GetRequiredService<MyClass<string>>();

        Assert.IsNull(my.MyClass2);
        p.Autowired(() => my);
        Assert.IsNotNull(my.MyClass2);
    }


    class MyClass<T>
    {
        [Autowired]
        public MyClass2 MyClass2 { get; set; }
    }

    class MyClass2
    {

    }
}
